<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="js/jquery-1.3.2.min.js"></script>
</head>
<body>
   <button id="btn1">前端向后端发送一个字符串</button>
   <br>
    <button id="btn2">前端向后端发送一个字符串(对象形式)</button>
   <br>
   <button id="btn3">前端向后端发送一个对象(对象形式)</button>

   <br>
   <button id="btn4">前端向后端发送一个对象(json字符串)</button>

   <br>
   <button id="btn5">前端向后端发送一个对象,后端使用map接受</button>
   <br>
   <button id="btn6">前端向后端发送一个集合</button>
</body>
<script>
    $("#btn1").click(function(){
        $.ajax({
            url:"json2/test1",
            type:"post",
            data:"hello world",
            contentType:"application/json", //设置前端发送给后端的数据格式
            success:function(data){
                console.log(data);
            }
        })
    })


    $("#btn2").click(function(){
        $.ajax({
            url:"json2/test2",
            type:"get",
            data:{"msg":"hello world"},
            success:function(data){
                console.log(data);
            }
        })
    })


    $("#btn3").click(function(){
        $.ajax({
            url:"json2/test3",
            type:"get",
            data:{
                "userId":1,
                "username":"shufen",
                "password":"123456",
                "userAge":18,
                "birthday":"2005-5-5",
                "email":"123456@qq.com"
            },
            success:function(data){
                console.log(data);
            }
        })
    })

    $("#btn4").click(function(){
        $.ajax({
            url:"json2/test4",
            type:"POST",
            data:`{
                "userId":1,
                "username":"shufen",
                "password":"123456",
                "userAge":18,
                "birthday":"2005-5-5",
                "email":"123456@qq.com"
            }`,
            contentType:"application/json",
            success:function(data){
                console.log(data);
            }
        })
    })

    $("#btn5").click(function(){
        $.ajax({
            url:"json2/test5",
            type:"POST",
            data:JSON.stringify({
                "userId":1,
                "username":"shufen",
                "password":"123456",
                "userAge":18,
                "birthday":"2005-5-5",
                "email":"123456@qq.com"
            }),
            contentType:"application/json",
            success:function(data){
                console.log(data);
            }
        })
    })

    $("#btn6").click(function(){
        $.ajax({
            url:"json2/test6",
            type:"POST",
            data:JSON.stringify([{
                "userId":1,
                "username":"zhangsan"
            },{
                "userId":2,
                "username":"lisi"
            }]),
            contentType:"application/json",
            success:function(data){
                console.log(data);
            }
        })
    })
</script>
</html>